# 设置最低要求的CMake版本
cmake_minimum_required(VERSION 3.10)

# 定义项目名称和语言
project(MotionPlanning CXX)
# SET(CMAKE_BUILD_TYPE Debug )
# 如果没有指定构建类型，则默认为Release
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
endif()

# 输出当前的构建类型
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

# 根据构建类型设置编译选项
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    message(STATUS "Configuring Debug build")
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++17 -O0")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
    message(STATUS "Configuring Release build")
    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++17 -O3")
endif()

# 查找Python3及其组件
find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)

# 创建一个INTERFACE库用于matplotlib_cpp依赖
add_library(matplotlib_cpp INTERFACE)
target_link_libraries(matplotlib_cpp INTERFACE
        Python3::Python
        Python3::Module
        )

# 如果找到NumPy，则链接它；否则定义宏WITHOUT_NUMPY
if(Python3_NumPy_FOUND)
    target_link_libraries(matplotlib_cpp INTERFACE Python3::NumPy)
else()
    target_compile_definitions(matplotlib_cpp INTERFACE WITHOUT_NUMPY)
endif()

# 查找fmt和spdlog库
find_package(fmt REQUIRED)
find_package(spdlog REQUIRED)

# 使用pkg-config查找yaml-cpp库
find_package(PkgConfig REQUIRED)
pkg_check_modules(YAML_CPP REQUIRED yaml-cpp>=0.5)

# 输出yaml-cpp的相关信息
message(STATUS "yaml-cpp found: ${YAML_CPP_FOUND}")
message(STATUS "yaml-cpp include dirs: ${YAML_CPP_INCLUDE_DIRS}")
message(STATUS "yaml-cpp libraries: ${YAML_CPP_LIBRARIES}")

# 添加头文件搜索路径
include_directories(
        "/usr/include/yaml-cpp"
        "/usr/include/eigen3"
        ${CMAKE_CURRENT_LIST_DIR}
        ${PROJECT_SOURCE_DIR}/include
        ${PROJECT_SOURCE_DIR}/3rdparty
)

# 收集源文件
file(GLOB SOURCE_FILES "${PROJECT_SOURCE_DIR}/src/*.cpp")

# 定义第三方库列表
set(3RDPARTY
        matplotlib_cpp
        fmt::fmt
        spdlog::spdlog
        )

# 添加可执行目标
add_executable(motion_planning ${SOURCE_FILES})

# 链接所有必要的库
target_link_libraries(motion_planning PRIVATE
        ${3RDPARTY}
        ${YAML_CPP_LIBRARIES}
        )

# 指定yaml-cpp的头文件目录给motion_planning目标
target_include_directories(motion_planning PRIVATE ${YAML_CPP_INCLUDE_DIRS})